<template>
  <div>
    <img src=".././assets/logo.png" />
    <h1>搜索变色</h1>
    <el-input
      v-model="input"
      style="width: 500px"
      placeholder="请输入内容"
      @input="inputChang"
    ></el-input>
    <div class="search-content" v-if="input">
      <div v-for="(item, index) in xialaData" :key="index">
        <span
          v-for="(el, ex) in item"
          :key="ex"
          :class="[el.indexOf(input) != -1 ? 'active' : '']"
        >
          {{ el }}
        </span>
      </div>
    </div>
  </div>
</template>

<script>
// 引入防抖节流
import { debounce } from '../libs/optimize'
export default {
  name: 'HelloWorld',
  data () {
    return {
      xialaData: ['1张三11', '李四2', '王五1', '赵六1'],
      input: ''
    }
  },
  methods: {
    //   给输入就触发的方法添加防抖操作，防止频繁触发
    inputChang: debounce(function (value) {
      console.log(value)
    })
  },
  mounted () {
    console.log('生命周期222')
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less">
// less本版太高报错需要降低版本
// https://www.cnblogs.com/live41/p/14723233.html
// 先移除之前版本：npm uninstall less-loader
// 下载指定版本：npm install less-loader@5.0.0 -D
.search-content {
  // position: absolute;
  // top: 50px;
  // left: 0;
  // width: calc(100% - 130px);
  margin: 0 auto;
  width: 500px;
  max-height: 300px;
  overflow-y: auto;
  background: #fff;
  z-index: 999;
  box-shadow: -1px 6px 7px 3px #5555552e;
  div {
    color: #333;
    font-size: 14px;
    padding-left: 30px;
    line-height: 40px;
    cursor: pointer;
    &:hover {
      background: #99999926;
      color: #3489f8;
    }
    .active {
      color: #3489f8;
    }
  }
}
</style>
